﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebProxyApplication.Blocked
{
    public partial class Blocked : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                AdjustDisplay();
            }
            catch (Exception ex)
            {
                ProxyLogger.Log.Error("Proxy blocked error occurred", ex);
            }
        }

        private void AdjustDisplay()
        {
            string blockCode = Request.QueryString["blockCode"];
            BlockedReason blockedReason;
            string reasonDetailMessage = null; // message to show the user
            Int32 pageRank = -99;

            lBlockCode.Text = blockCode;
            if (!Enum.TryParse<BlockedReason>(blockCode, out blockedReason))
            {
                blockedReason = BlockedReason.Unknown;
            }
            if(Request.QueryString["PageRank"] != null)
                pageRank = Int32.Parse(Request.QueryString["PageRank"]);
            switch (blockedReason)
            {
                case BlockedReason.InvalidCertificate:
                    reasonDetailMessage = "The security certificate for this site is not trusted.";
                    break;
                case BlockedReason.PhishingSite:
                    reasonDetailMessage = "The requested url is a phishing site.";
                    break;
                case BlockedReason.LowPageRank:
                    reasonDetailMessage = "The requested url has a low page rank and is not trusted.";
                    lPageRank.Text = "Page Rank value:" + pageRank.ToString();
                    break;
                case BlockedReason.Unknown:
                default:
                    reasonDetailMessage = "Unknown blocked reason occurred";
                    break;
            }

            litBlockedReasonDetail.Text = reasonDetailMessage;
        }
    }
}